declare condition
Declare a condition variable
Syntax
declare_condition:
DECLARE cond_name CONDITION [FOR SQLSTATE [VALUE] "string"]
| DECLARE cond_name CONDITION [FOR SQLCODE [VALUE] code_name]
Description
A condition declaration provides the ability to define a name for a particular exception condition. The FORSQLSTATE clause associates cond_name with the specified SQLSTATE value (a five-character string, e.g., "07001"). The (non-standard) for SQLCODE clause associates cond_name with the specified RaimaDB-specific error code. A condition declaration that is not associated with a SQLSTATE or SQLCODE value declares a user exception. Exception handlers for user conditions are invoked through execution of the SIGNAL statement and are the primary uses for named conditions since the DECLARE HANDLER statement (see below) can explicitly specify the RaimaDB SQL exceptions to be handled by it without having to have those explicitly named by a prior DECLARE CONDITION.
Example
create procedure nested_handler
begin
declare v1 int default 1;
declare v2 int default 2;
declare block char(5) default "outer";
declare c1 condition;
declare c2 condition;
declare continue handler for c1
begin
set v1 = 10;
set v2 = 20;
end;
select block, v1, v2;
begin
declare block char(5) default "inner";
declare continue handler for c1 set v1 = 100;
declare continue handler for c2 set v2 = 200;
select block, v1, v2;
signal c1;
select block, c1, v1, v2;
signal c2;
select block, c2, v1, v2;
end;
signal c1;
select block, c1, v1, v2;
end;
See Also